<template>
    <div>
<h1>新增病房</h1>
<table class="table">
    <tbody>
        <tr>
            <td>病房号</td>
            <td>
                <input type="text" v-model="data.roomIds">
            </td>
        </tr>
        <tr>
            <td>病房名称</td>
            <td>
                <input type="text" v-model="data.roomName">
            </td>
        </tr>
        <tr>
            <td>所属科室</td>
            <td>
                <select v-model="data.ksId">
                    <option value="0">请选择科室</option>
                    <option v-for="d in dataps" :value="d.kid">{{d.kName}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>床位总数</td>
            <td>
                <input type="text" v-model="data.sumNUm">
            </td>
        </tr>
        <tr>
            <td>空闲床位</td>
            <td>
                <input type="text" v-model="data.badnum">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="新增" class="btn btn-success" @click="AddRoom">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
var router=useRouter();
onMounted(()=>{
    Bind();
})
const data=ref({
      "roomId": 0,
  "roomIds": 0,
  "roomName": "",
  "ksId": 0,
  "sumNUm": 0,
  "states": "",
  "badnum": 0,
  "createTime": "2025-05-19T02:54:40.257Z"
})

const AddRoom=()=>{
    if(data.value.roomName=="")
{
    alert("病房名称不能为空");
    return;
}
if(data.value.roomName.length>6)
{
    alert("病房名称不能超过6个字符")
    return;
}
    axios.post("/api/Room/AddRoom",data.value).then(res=>{
        if(res.data>0)
    {
        alert("新增成功");
        router.push({path:"/RoomXs"})
    }
    else
    {
        alert("新增失败");
    }
    })
}




//绑定下拉框
const dataps=ref([{
     "kid": 0,
    "kName": "",
}])

const Bind=()=>{
    axios.get("/api/Ks/GetDc",{params:dataps.value}).then(res=>{
        dataps.value=res.data;
    })
}
</script>

<style scoped>

</style>